<script>
	import Vue from 'vue'
	import httpConfig from '@/config/httpConfig.js'
	export default {
		onLaunch: function() {
			uni.getSystemInfo({
			    success: function(e) {
			    // #ifndef MP
			    Vue.prototype.StatusBar = e.statusBarHeight;
					if (e.platform == 'android') {
			            Vue.prototype.CustomBar = e.statusBarHeight + 50;
			        } else {
			            Vue.prototype.CustomBar = e.statusBarHeight + 45;
			        };
			        // #endif
			        // #ifdef MP-WEIXIN
			        Vue.prototype.StatusBar = e.statusBarHeight;
			        let custom = wx.getMenuButtonBoundingClientRect();
			        Vue.prototype.Custom = custom;
			        Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
			        // #endif       
			        // #ifdef MP-ALIPAY
			        Vue.prototype.StatusBar = e.statusBarHeight;
			        Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
			        // #endif
			    },
			})
			const data = {name: 'cdsasa', age: 30}
			this.$store.dispatch("set_userinfo", data)
			// #ifdef MP-WEIXIN
			uni.login({
				provider: 'weixin',
				success: res => {
					let params = {
						client_id: httpConfig.server.appId,
						code: res.code,
					}
					let timestamp = Date.parse(new Date());
					console.log('获取 token  的时间戳', timestamp)
					
					this.$api.getToken(params).then(res => {
						if(res) {
							let tokenRefreshTime = (res.expire_in -  120) * 1000 + timestamp
							this.$store.dispatch("set_token_refresh_time", tokenRefreshTime)
							this.$store.dispatch("set_userinfo", res)
							let getUserInfo = false
							let getPhoneNumber = false
							if(res.avatar !='' && res.nickname !='') getUserInfo = true
							if(res.mobile !='') getPhoneNumber = true
							console.log(res.uid)
						
							this.$store.dispatch("set_authflag", {
								getUserInfo, 
								getPhoneNumber
							})
							if(res.uid && res.uid != 0) {
								console.log('标识 已经有了啊')
								this.$api.getTaskToken({
									code: res.token
								}).then(result => {
									this.$store.dispatch("set_task_userinfo", result)
									if(result){
										if(result.is_sku_actived == 1) {
											this.$store.dispatch("set_authflag", {
												hasShop: true 
											})
										}else {
											this.$store.dispatch("set_authflag", {
												hasShop: false 
											})
										}
										if(result.douyin_id!=''){
											this.$store.dispatch("set_authflag", {
												bindDouyin: true 
											})
										}else{
											this.$store.dispatch("set_authflag", {
												bindDouyin: false 
											})
										}
										uni.switchTab({
										    url: '/pages/index/index'
										});
										this.$isResolve()
									}
								})
							}else{
								uni.switchTab({
								    url: '/pages/index/index'
								});
								this.$isResolve()
							}
						}
					})
					// this.$isResolve()
				},
				fail(err) {
					console.log('获取 code 失败')
				}
			})
			// #endif
			console.log('')
		},
		onShow: function() {
			console.log('App Show')
			uni.hideTabBar()
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style>
	/*每个页面公共css */
	/* @import "colorui/main.css"; */
	/* @import "colorui/icon.css"; */
</style>
